home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / 1118.zip / 1118.TXT next >
Text File  |  1993-03-08  |  5KB  |  131 lines

  1.                                 FYI
  2.  
  3. (Note: The origin of this information may be internal or external to Novell. 
  4. Novell makes every effort within its means to verify this information. 
  5. However, the information provided in this document is FOR YOUR INFORMATION
  6. only.  Novell makes no explicit or implied claims as to the validity of this
  7. information.) 
  8.  
  9.           TITLE:  BATCH PROGRAMMING 
  10.    DOCUMENT ID#:  FYI-M-1118
  11.            DATE:  10FEB93
  12.         PRODUCT:  DR DOS
  13. PRODUCT VERSION:  6.0
  14.      SUPERSEDES:  13OCT92
  15.  
  16.         SYMPTOM:  WRITING A BATCH PROGRAM THAT CAN EXECUTE MULTIPLE TIMES &
  17. PERFORM IT'S DEFINED TASK ONLY ONCE
  18.  
  19.   ISSUE/PROBLEM:  Batch programming capabilities were recently changed.  These
  20. changes became effective with COMMAND.COM files dated after 4/7/92.  The latest
  21. COMMAND.COM is available via CompuServe or the Novell DSG Host BBS at
  22. 408-649-3443.
  23.  
  24.        SOLUTION:  This document contains a sample batch file that makes use of
  25. the changes contained in the updated COMMAND.COM.  This sample file
  26. demonstrates the creation of a batch program that can be executed a number of
  27. times but will perform the defined task only once a day.
  28.  
  29. 1.   Create a file called DTFRCMP.TXT that contains the current
  30.      date information by typing the following from the command
  31.      line:  C:\>DATE >DTFRCMP.TXT
  32.      Press the Enter key twice to be returned to the prompt.
  33.  
  34. 2.   Create a file called CR using the EDITOR (EDITOR.EXE). 
  35.      This file will contain a carriage return. To create this file:
  36.  
  37.      a.   Type EDITOR CR at the command prompt 
  38.      b.   When prompted, "do you wish to create a new file?"
  39.           Type Y.
  40.      c.   You will then be in the EDITOR.  Enter a carriage return
  41.           by pressing the ENTER key once.
  42.      d.   Save the file by holding the CTRL key down and then
  43.           typing KX.
  44.  
  45. 3.   Create the main batch file that performs the daily routine.
  46.  
  47.      a.   From the command prompt (C:\>) type: EDITOR TEST.BAT
  48.      b.   When prompted, "do you wish to create a new file?" 
  49.           Type Y.
  50.      c.   Proceed to type the following lines (creating the file):
  51.  
  52. @ECHO OFF
  53. REM This logs the date information into a file.
  54. DATE <CR >INF.TXT
  55. REM This compares the preexisting date information
  56. REM with the date information that was just created.
  57. REM It creates a file with this information.
  58. COMP INF.TXT DTFRCMP.TXT >CMP.RZT
  59.  
  60. REM This looks for the word "failure" in the created
  61. REM text file. (This would be an indication that the
  62. REM files are the same if "failure" was not found)...
  63. REM Thus telling us that this batch file has already
  64. REM been run today.
  65. REM It pipes the results into a file.
  66. FIND "FAILURE" CMP.RZT >DECIDER.TXT
  67.  
  68. REM If "failure" was found, then the file that was 
  69. REM created will have a file size.  If it was not
  70. REM found then it will have a zero byte file size.
  71. REM This will try to copy the file to another file.
  72. REM If the original file is a zero byte file then
  73. REM this procedure will fail because the COPY 
  74. REM command cannot copy a zero byte file.
  75. COPY DECIDER.TXT FINAL.TXT >NUL
  76.  
  77. REM This checks to see if the final file was created.
  78. REM If it was not, then the daily routine will be
  79. REM bypassed...this batch file has already been run today.
  80. IF NOT EXIST FINAL.TXT GOTO FINAL
  81.  
  82. REM If this section has been reached, then the batch
  83. REM file has not been run today and it is going to 
  84. REM execute the once-a-day command that it is intended
  85. REM to execute. This can be any command of your choosing
  86. REM as long as it works from the DOS prompt.  The one that
  87. REM has been chosen here is a command that copies the
  88. REM config.sys file to a filename called ITWORKED.SYS.
  89. :COPY
  90. COPY C:\CONFIG.SYS C:\ITWORKED.SYS >NUL
  91. ECHO Executing once-a-day routine...
  92. REM This creates a new date-comparison file so that the
  93. REM next time that this batch file is run it will see 
  94. REM that it has already been run today.
  95.  
  96. COPY INF.TXT DTFRCMP.TXT >NUL
  97.  
  98. REM This deletes the final comparison file that was created
  99. REM today.
  100. DEL FINAL.TXT
  101.  
  102. REM This cleans up all of the extra files and exits.
  103. :END
  104. DEL INF.TXT
  105. DEL CMP.RZT
  106. DEL DECIDER.TXT
  107. EXIT
  108.  
  109. REM This tells you that it has already been run today.
  110. :FINAL
  111. echo Daily routine has already been run today.
  112. GOTO END
  113.  
  114.  
  115. If TEST.BAT is executed many times daily, it will create
  116. the file ITWORKED.SYS just once a day.
  117.  
  118.            NOTE:  If you attempt to run this batch file on the same day that it
  119. was created a message will be returned that this routine has already been run
  120. today.  This is because the information in the DTFRCMP.TXT file is the same as
  121. the current day's date.  If you wish to test it on the same day that the file
  122. was created, you will have to change the date using the date command.
  123.  
  124. This file can be incorporated in the AUTOEXEC.BAT file to execute every time
  125. the computer is turned on.  To do this, use the EDITOR and add the following
  126. line just before the line :DRDOSEND: 
  127.  
  128. CALL TEST.BAT
  129.  
  130. Some possible uses of such a batch file would be running a daily virus scan,
  131. system diagnostics or the disk optimizer.